﻿#ifndef XUNFEI_AIUI_H
#define XUNFEI_AIUI_H

#include <QObject>
#include <QApplication>
#include <QDateTime>
#include <QAudioInput>
#include <QAudioFormat>
#include <QAudioDeviceInfo>
#include <QFile>
#include <QNetworkAccessManager>
#include <QNetworkRequest>
#include <QNetworkReply>
#include <QUrl>
#include <QUrlQuery>
#include <QJsonDocument>
#include <QJsonObject>
#include <QJsonArray>
#include <QCryptographicHash>   //一种生成加密散列的方法,如MD4、MD5加密
#include <QElapsedTimer>
#include <QSettings>

class XunFei_AIUI : public QObject
{
    Q_OBJECT
public:
    explicit XunFei_AIUI(QObject *parent = nullptr);
    ~XunFei_AIUI();
    void set_parameters(const QString& app_id, const QString& auth_id, const QString& api_key);

public slots:
    void startRecord();
    void stopRecord();
    void on_AudioInput_stateChange(QAudio::State newState);
    void ask_iFLY();
    void iFLY_reply(QNetworkReply *reply);
signals:
    void xunfei_answer(const QString& content);
    void iat_result(const QString& content);
    void err_msg(const QString msg);
    void cmd_close();
private:
//    QString app_id = "6b653222";
//    QString auth_id = "29307972fe97ef00a74d2d5f8fe5a9dc";
//    QString api_key = "77419224172902c4098920586053f294";
    QString app_id = "";
    QString auth_id = "";
    QString api_key = "";
    const QString AIUI_url = "https://openapi.xfyun.cn/v2/aiui";
    QFile* dest_file;
    QAudioInput* AudioInput;
    QNetworkAccessManager* NetAccManager;
    QNetworkRequest Request;
    QElapsedTimer ETimer;
};

#endif // XUNFEI_AIUI_H
